package ${configs.packagePath}.exception;

import ${configs.packagePath}.common.IBaseResponseCode;
import ${configs.packagePath}.enums.BaseCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <Description>
 * 自定义异常
 * @author Jun Lee
 * @version 1.0
 * @createDate ${date}
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CustomException extends Exception {

    private Integer code = IBaseResponseCode.ERROR_CODE;

    public CustomException(String message) {
        super(message);
    }


    public static Exception throwException(String message) throws CustomException {
        throw new CustomException(message);
    }

    public static Exception throwException(String message,Integer code) throws CustomException {
        CustomException exception = new CustomException(message);
        exception.setCode(code);
        throw exception;
    }

    public static Exception throwException(BaseCodeEnum codeEnum) throws CustomException {
        CustomException exception = new CustomException(codeEnum.getMessage());
        exception.setCode(codeEnum.getCode());
        throw exception;
    }
}
